import request from "@/util/request";
import type { Page } from '@/api/types/page'
import type { Ingredient, IngredientsSearchParam } from "./types";
import type { AnyColumn } from "element-plus/es/components/table-v2/src/common.mjs";

const API: string = '/dishes-service/ingredients'
/**
 * 接口
 * POST /dishes-service/ingredients
 * GET /dishes-service/ingredients/list
 * PUT /dishes-service/ingredients/{id}
 * DELETE /dishes-service/ingredients/{id}
 */
export const getIngredientsList = (form: IngredientsSearchParam) => {
    return request<Page<Ingredient>, Page<Ingredient>>({
        url: API + '/list',
        method: 'GET',
        params: form
    })
}

/* 食材添加 */
export const addIngredients = (form:Ingredient) =>{
    // 接受参数类型, 接受参数类型 post请求的data类型
    return request<any,any,Ingredient>({
        url:API,
        method:'POST',
        data:form
    })
}

/* 食材修改 */
export const updateIngredients = (id:number,form:Ingredient) =>{
    // 接受参数类型, 接受参数类型 post请求的data类型
    return request<any,any,Ingredient>({
        url:`${API}/${id}`,
        method:'PUT',
        data:form
    })
}

/* 食材刪除 */
export const deleteIngredient = (id:number) =>{
    // 接受参数类型, 接受参数类型 post请求的data类型
    return request<any,any,Ingredient>({
        url:`${API}/${id}`,
        method:'DELETE',
    })
}

export const typeById = (type:any) => {
    return request<Ingredient[],Ingredient[]>({
        url: API + '/listByType',
        method: 'GET',
        params: {
            type
        }
    })
}